package org.openzip.openzip.archiving.gui;


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.util.Collection;

import org.openzip.openzip.archiving.logic.IOpenZipArchiver;
import org.openzip.openzip.gui.util.FileAdapter;
import org.openzip.openzip.gui.util.layout.SkeletonGUI;


/**
 * This is an implementation of <code>IArchiverUI</code> interface.<br>
 * It provides a graphical user interface for the archiving logic. For seeing
 * how the GUI looks like, refer to the specification.
 * 
 * @author Jakub Závěrka
 */
public class ArchiverGUI extends SkeletonGUI  implements IArchiverUI
{
	protected IOpenZipArchiver logic;
	
	public ArchiverGUI(){
		super();
		super.setFilePanel(new ArchiverFilePanel());
		super.setAdapter(new FileAdapter());
		super.setFormLabel("OpenZIP Archiver");
		super.setMakeArchiveButtonLabel("Make Archive");
		super.prepareComponents();
	}
	
	/**
	 * Testing method.
	 */
	public static void main(String[] args) {
		/*try{
			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		}
		catch(Exception e){
			e.printStackTrace();
		}*/
		ArchiverGUI gui = new ArchiverGUI();
		gui.useUI(null);
	}

	
	/**
	 * {@inheritDoc} <br>
	 * This implementaion will display an empty environment.
	 */
	@Override
	public void useUI(IOpenZipArchiver logic) {
		this.logic = logic;
		mainWindow.setVisible(true);
	}

	/**
	 * {@inheritDoc} <br>
	 * This implementaion will display the environment with specified files
	 * pre-selected. Changes will be reflected in the tree, folder list and file
	 * list. Other files may get selected and the pre-selected files amy get
	 * de-selected.
	 */
	@Override
	public void useUI(IOpenZipArchiver logic, Collection<File> files) {
		throw new UnsupportedOperationException("Not yet implemented.");
	}
	
	private class MakeArchiveListener implements ActionListener {
		@Override
		public void actionPerformed(ActionEvent e) {
			logic.makeArchive(filePanel.getFile(), globalSelectionModel
					.getSelectedFiles());
		}
	}

}
